<template>
	<view class="container">
		<!-- 顶部筛选 -->
		<view class="head">
			<view class="head-block">
				<view class="filtrate" @click="tabFiltrate">
					<view>筛选</view>
					<image class="filtrate-img" src="../../../static/icon/wx.png" mode=""></image>
				</view>
			</view>
			<view class="filtrate-content" :class="active ? 'show' : 'hide' ">
				<view class="filtrate-content-list">
					<view class="filtrate-content-list-item">
						<view class="title">户型</view>
						<radio-group>
							<label>
								<radio value="r1" checked="true" />全部
							</label>
							<label>
								<radio value="r2" />自建房
							</label>
							<label>
								<radio value="r2" />别墅
							</label>
							<label>
								<radio value="r2" />小区房
							</label>
						</radio-group>
					</view>
					<view class="filtrate-content-list-item">
						<view class="title">租金</view>
						<radio-group>
							<label>
								<radio value="r1" checked="true" />0-1000
							</label>
							<label>
								<radio value="r2" />1000-2000
							</label>
							<label>
								<radio value="r2" />2000-3000
							</label>
							<label>
								<radio value="r2" />3000-4000
							</label>
							<label>
								<radio value="r2" />4000-5000
							</label>
							<label>
								<radio value="r2" />5000以上
							</label>
						</radio-group>
					</view>
					<view class="filtrate-content-list-item">
						<view class="title">地区</view>
					</view>
					<!-- 重置or确认 -->
					<view class="filtrate-btn">
						<view class="filtrate-btn-list">
							<view class="filtrate-btn-list-item">重置</view>
							<view class="filtrate-btn-list-item">确定</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 列表 -->
		<view class="list">
			<view class="list-item" v-for="(item, index) in rentList" :key="index" @click="toDetail(item.id)">
				<image :src="item.images[0]" mode="aspectFill"></image>
				<view class="rent-info">
					<view class="rent-info-name">
						{{item.title}}
					</view>
					<view class="rent-info-tags">
						<view class="tags-item">
							{{item.house_type_text}}
						</view>
						<view class="tags-item" v-if="item.floor_type == 1">低楼层</view>
						<view class="tags-item" v-if="item.floor_type == 2">中楼层</view>
						<view class="tags-item" v-if="item.floor_type == 3">高楼层</view>
						<view class="tags-item">
							{{item.pay_type}}
						</view>
						<view class="tags-item">
							{{item.proportion}}㎡
						</view>
					</view>
					<view class="rent-info-bottom">
						<view class="rent-info-price">{{item.price}}<text class="tip">元/月</text></view>
						<view class="rent-info-date">{{item.updated_at}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="footer" v-show="showMore">
			暂无更多数据
		</view>
		<!-- 遮罩 -->
		<view :class="active ? 'mask' : '' " @click="close"></view>
	</view>
</template>

<script>
	import HOME from '@/api/home/index.js'

	export default {
		data() {
			return {
				active: false,
				rentList: [],
				showMore: false,
				page: 1
			}
		},
		mounted() {
			this.getRentList();
		},
		methods: {
			tabFiltrate() {
				this.active = !this.active;
			},
			getRentList() {
				uni.showLoading({
					title: '获取数据中',
					mask: true
				})
				HOME.getRentList(this.page, 10, 2).then(res => {
					uni.hideLoading();
					if (res.data.data.length == 0) {
						this.showMore = true;
					}
					this.rentList = this.rentList.concat(res.data.data);
				})
			},
			// 下拉刷新
			onReachBottom() {
				this.page += 1;
				if(!this.showMore) {
					this.getRentList();
				}
			},
			toDetail(val) {
				uni.navigateTo({
					url: 'detail/index?id=' + val
				})
			},
			close() {
				this.active = !this.active;
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		height: 100vh;
		background-color: #f1f1f1;
	}

	.head {
		position: fixed;
		width: 100%;
		background-color: #FFFFFF;
		z-index: 99;

		.head-block {
			display: flex;
			justify-content: space-between;
			align-items: center;

			height: 6vh;
			padding: 0 20rpx;

			.tabs {
				display: flex;

				font-size: 30rpx;
				color: #999;

				.tabs-item {
					padding-right: 20rpx;
				}
			}

			.filtrate {
				display: flex;
				align-items: center;

				font-size: 30rpx;

				image {
					width: 30rpx;
					height: 30rpx;
					margin-left: 10rpx;
				}
			}
		}

		.show {
			display: block;
		}

		.hide {
			display: none;
		}

		.filtrate-content {
			position: absolute;
			top: 6vh;
			right: 0;
			bottom: 0;
			left: 0;

			.filtrate-content-list {
				padding: 0 10rpx;
				background-color: #ffffff;

				.filtrate-content-list-item {
					font-size: 28rpx;

					.title {
						font-size: 36rpx;
						font-weight: 800;
					}

					checkbox-group,
					radio-group {
						display: flex;
						flex-wrap: wrap;

						margin: 20rpx 0;

						label {
							width: 33%;
							padding: 10rpx 0;
						}
					}

					checkbox,
					radio {
						transform: scale(0.8)
					}
				}

				.filtrate-btn {
					border-top: 1rpx #ccc solid;

					.filtrate-btn-list {
						display: flex;
						padding: 20rpx 15rpx;
						font-size: 30rpx;

						.filtrate-btn-list-item {
							text-align: center;
							width: 365rpx;
						}
					}
				}
			}
		}
	}

	.list {
		padding: 6vh 0;

		.list-item {
			display: flex;
			margin: 20rpx;
			padding: 20rpx;
			border-radius: 30rpx;
			box-shadow: 0px 10rpx 20rpx #ccc;
			background-color: #FFFFFF;

			image {
				width: 200rpx;
				height: 200rpx;
				margin-right: 10rpx;
			}

			.rent-info {
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				width: 500rpx;

				.rent-info-name {
					font-size: 38rpx;
					font-weight: 1000;
				}

				.rent-info-tags {
					display: flex;
					flex-wrap: wrap;

					.tags-item {
						margin-right: 10rpx;
						padding: 4rpx 12rpx;
						border-radius: 10rpx;
						background-color: #2A9F93;
						color: #FFFFFF;
						font-size: 26rpx;
					}
				}

				.rent-info-bottom {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.rent-info-price {
						color: brown;

						.tip {
							margin-left: 4rpx;
							font-size: 24rpx;
						}
					}

					.rent-info-date {
						font-size: 24rpx;
					}
				}
			}
		}
	}
	
	.footer {
		display: flex;
		justify-content: center;
		align-items: center;
		
		height: 100rpx;
		font-size: 28rpx;
		color: #999;
	}

	.mask {
		position: fixed;
		left: 0;
		top: 0;
		width: 100vw;
		height: 100vh;
		background: rgba(0, 0, 0, .5);
		z-index: 98;
	}
</style>
